home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / grx / echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-24  |  6.6 KB  |  235 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** INFORMATION ABOUT THE LOW-LEVEL ECHOING DRIVERS
  5.  
  6. SRGP__initEchoModule ()
  7.    Must be called once, during initialization.
  8.    The echo-attribute globals must have already been given
  9.       default initial values!
  10.  
  11. SRGP__updateLocatorRubberAnchor ()
  12.    Acesses current locator rubber anchor from globals.
  13.    May be called whether rubber echo is active or not.
  14.  
  15. SRGP__enableLocatorRubberEcho ()
  16.    Accesses current locator measure info from global variables.
  17.    May be called carelessly:
  18.       1) Will not re-enable if already enabled
  19.       2) Will refuse to enable echo for a device that is:
  20.       A) not active currently, and
  21.       B) not in a state for which echo is desired
  22.  
  23. SRGP__updateLocatorRubberEcho ()
  24.    Accesses current locator measure info from global variables.
  25.    May be called carelessly:
  26.       Will not update if device is currently disabled.
  27.  
  28. SRGP__disableLocatorRubberEcho ()
  29.    May be called carelessly:
  30.       Will not re-disable if already disabled
  31.  
  32.  
  33. SRGP__updateLocatorCursorShape ()
  34.    May be called whether or not the cursor echo is active.
  35.  
  36. SRGP__enableLocatorCursorEcho ()
  37. SRGP__disableLocatorCursorEcho ()
  38.       May be called carelessly.
  39.  
  40. SRGP__updateRawCursorPosition ()
  41.       Accesses cur_locator_measure from global variables.
  42.       Informs the underlying graphics package of the desired "cursor warp".
  43.       Automatically updates any type of locator echo: cursor or rubber.
  44.  
  45.  
  46. SRGP__updateKeyboardEchoAttributes ()
  47.    May be called whether or not key echo is active.
  48.    Obtains attributes from global variables.
  49.  
  50. SRGP__enableKeyboardEcho ()
  51. SRGP__updateKeyboardEcho ()
  52. SRGP__disableKeyboardEcho ()
  53.       Similar to above: may be called carelessly.
  54.  
  55. **/
  56.  
  57.  
  58. /* FOR LOCATOR ECHO */
  59.  
  60.  
  61. static locator_echo_mode = NO_ECHO;
  62. static int echo_rubber_x;        /* rubber echo X anchor position */
  63. static int echo_rubber_y;        /* rubber echo Y anchor position */
  64.  
  65. /* FOR KEYBOARD ECHO */
  66. static boolean keyboard_echo_is_active=FALSE;
  67. static int echo_keybd_x = 0;        /* X position */
  68. static int echo_keybd_y = 0;        /* Y position */
  69. static int echo_keybd_w = 0;        /* width  of current echo */
  70. static int echo_keybd_h = 0;        /* height of current echo */
  71.  
  72. GrTextOption srgp__grx_keyboard_echo_textopt;
  73.  
  74. void SRGP__initEchoModule(void)
  75. {
  76.     /* INITIALIZE KEYBOARD: font, color, origin */
  77.     SRGP__updateKeyboardEchoAttributes();
  78.  
  79.     /* DEFAULT LOCATOR-ECHO RUBBER ANCHOR (same as keyboard echo) */
  80.     echo_rubber_x = echo_keybd_x;
  81.     echo_rubber_y = echo_keybd_y;
  82. }
  83.  
  84. static void cursorecho(int mode)
  85. {
  86.     switch(mode) {
  87.       case NO_ECHO:
  88.         if(locator_echo_mode != NO_ECHO) MouseEraseCursor();
  89.         locator_echo_mode = NO_ECHO;
  90.         return;
  91.       case CURSOR:
  92.         MouseSetCursorMode(M_CUR_NORMAL);
  93.         break;
  94.       case RUBBER_LINE:
  95.         MouseSetCursorMode(M_CUR_LINE,
  96.         echo_rubber_x,
  97.         echo_rubber_y,
  98.         COLORINDEX(srgp__canvasTable[0].attributes.color) ^
  99.         COLORINDEX(srgp__canvasTable[0].attributes.background_color)
  100.         );
  101.         break;
  102.       case RUBBER_RECT:
  103.         MouseSetCursorMode(M_CUR_RUBBER,
  104.         echo_rubber_x,
  105.         echo_rubber_y,
  106.         COLORINDEX(srgp__canvasTable[0].attributes.color) ^
  107.         COLORINDEX(srgp__canvasTable[0].attributes.background_color)
  108.         );
  109.         break;
  110.     }
  111.     if(locator_echo_mode == NO_ECHO) MouseDisplayCursor();
  112.     locator_echo_mode = mode;
  113. }
  114.  
  115. void SRGP__enableLocatorRubberEcho(void)
  116. {
  117.     if(srgp__cur_mode[LOCATOR] == INACTIVE) return;
  118.     if(srgp__cur_locator_echo_type <= CURSOR) return;
  119.     echo_rubber_x = srgp__cur_locator_echo_anchor.x;
  120.     echo_rubber_y = SCREENFIXED(srgp__cur_locator_echo_anchor.y);
  121.     cursorecho(srgp__cur_locator_echo_type);
  122. }
  123.  
  124. void SRGP__disableLocatorRubberEcho(void)
  125. {
  126.     if(srgp__cur_mode[LOCATOR] == INACTIVE) return;
  127.     if(srgp__cur_locator_echo_type <= CURSOR) return;
  128.     cursorecho(CURSOR);
  129. }
  130.  
  131. void SRGP__updateLocatorRubberEcho(void)
  132. {
  133.     return;        /* DUMMY HERE !!! */
  134. }
  135.  
  136. void SRGP__updateLocatorRubberAnchor(void)
  137. {
  138.     echo_rubber_x = srgp__cur_locator_echo_anchor.x;
  139.     echo_rubber_y = SCREENFIXED(srgp__cur_locator_echo_anchor.y);
  140.     if(srgp__cur_mode[LOCATOR] == INACTIVE) return;
  141.     if(srgp__cur_locator_echo_type <= CURSOR) return;
  142.     cursorecho(locator_echo_mode);
  143. }
  144.  
  145. void SRGP__enableLocatorCursorEcho(void)
  146. {
  147.     if(srgp__cur_mode[LOCATOR] == INACTIVE) return;
  148.     if(srgp__cur_locator_echo_type < CURSOR) return;
  149.     cursorecho(srgp__cur_locator_echo_type);
  150. }
  151.  
  152. void SRGP__disableLocatorCursorEcho(void)
  153. {
  154.     if(srgp__cur_mode[LOCATOR] == INACTIVE) return;
  155.     cursorecho(NO_ECHO);
  156. }
  157.  
  158. void SRGP__updateLocatorCursorShape(void)
  159. {
  160.     MouseSetCursor(srgp__cursorTable[srgp__cur_cursor]);
  161. }
  162.  
  163. /** KEYBOARD ECHO **/
  164.  
  165. static void DrawText(void)
  166. {
  167.     char *p = srgp__cur_keyboard_measure.buffer;
  168.     int len = srgp__cur_keyboard_measure_length;
  169.     int www = GrStringWidth(p,len,&srgp__grx_keyboard_echo_textopt);
  170.  
  171.     GrDrawString(p,len,echo_keybd_x,echo_keybd_y,&srgp__grx_keyboard_echo_textopt);
  172.     if(www < echo_keybd_w) GrFilledBox(echo_keybd_x+www,
  173.         echo_keybd_y,
  174.         echo_keybd_x+echo_keybd_w-1,
  175.         echo_keybd_y+echo_keybd_h-1,
  176.         srgp__grx_keyboard_echo_textopt.txo_bgcolor.v
  177.     );
  178.     echo_keybd_w = www;
  179. }
  180.  
  181. static void EraseText(void)
  182. {
  183.     if(echo_keybd_w > 0) GrFilledBox(echo_keybd_x,
  184.         echo_keybd_y,
  185.         echo_keybd_x+echo_keybd_w-1,
  186.         echo_keybd_y+echo_keybd_h-1,
  187.         srgp__grx_keyboard_echo_textopt.txo_bgcolor.v
  188.     );
  189.     echo_keybd_w = 0;
  190. }
  191.  
  192. void SRGP__enableKeyboardEcho(void)
  193. {
  194.     if(!keyboard_echo_is_active) {
  195.         if(srgp__cur_mode[KEYBOARD] != INACTIVE) {
  196.         if(srgp__cur_keyboard_processing_mode == EDIT) {
  197.             keyboard_echo_is_active = TRUE;
  198.             DrawText();
  199.         }
  200.         }
  201.     }
  202. }
  203.  
  204. void SRGP__disableKeyboardEcho(void)
  205. {
  206.     if(keyboard_echo_is_active) {
  207.         EraseText();
  208.         keyboard_echo_is_active = FALSE;
  209.     }
  210. }
  211.  
  212. void SRGP__updateKeyboardEcho(void)
  213. {
  214.     if(keyboard_echo_is_active) DrawText();
  215. }
  216.  
  217. void SRGP__updateKeyboardEchoAttributes(void)
  218. {
  219.     if(keyboard_echo_is_active) EraseText();
  220.     memset(&srgp__grx_keyboard_echo_textopt,0,sizeof(srgp__grx_keyboard_echo_textopt));
  221.     srgp__grx_keyboard_echo_textopt.txo_font =
  222.         srgp__fontTable[srgp__cur_keyboard_echo_font];
  223.     srgp__grx_keyboard_echo_textopt.txo_fgcolor.v =
  224.         COLORINDEX(srgp__cur_keyboard_echo_color);
  225.     srgp__grx_keyboard_echo_textopt.txo_bgcolor.v =
  226.         COLORINDEX(srgp__canvasTable[0].attributes.background_color);
  227.     srgp__grx_keyboard_echo_textopt.txo_xmag = 1;
  228.     srgp__grx_keyboard_echo_textopt.txo_ymag = 1;
  229.     echo_keybd_h = GrFontHeight(&srgp__grx_keyboard_echo_textopt);
  230.     echo_keybd_x = srgp__cur_keyboard_echo_origin.x;
  231.     echo_keybd_y = SCREENFIXED(srgp__cur_keyboard_echo_origin.y) - ((echo_keybd_h * 5) / 7);
  232.     if(keyboard_echo_is_active) DrawText();
  233. }
  234.  
  235.